package my1024.behaviors;

//TODO REMOVE not used

import java.awt.AWTEvent;
import java.awt.event.KeyEvent;
import java.util.Enumeration;

import javax.media.j3d.Behavior;
import javax.media.j3d.WakeupCriterion;
import javax.media.j3d.WakeupOnAWTEvent;

public class MoveBehavior extends Behavior {
	private WakeupCriterion AWTEventCondition;

	public MoveBehavior() {
		this.AWTEventCondition = new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED);
	}

	@Override
	public void initialize() {
		this.wakeupOn(AWTEventCondition);
	}

	@Override
	public void processStimulus(Enumeration criteria) {
		WakeupCriterion wakeup;
		AWTEvent[] event;

		while (criteria.hasMoreElements()) {
			wakeup = (WakeupCriterion) criteria.nextElement();
			if (wakeup instanceof WakeupOnAWTEvent) {
				event = ((WakeupOnAWTEvent) wakeup).getAWTEvent();
				for (int i = 0; i < event.length; ++i) {
					if (KeyEvent.KEY_PRESSED == event[i].getID()) {
						processKeyEvent((KeyEvent) event[i]);
					}
				}
			}
		}

		this.wakeupOn(AWTEventCondition);
	}

	private void processKeyEvent(KeyEvent keyEvent) {
		switch (keyEvent.getKeyCode()) {
		case KeyEvent.VK_UP:
			System.out.println("UP");
			break;
		case KeyEvent.VK_DOWN:
			System.out.println("DOWN");
			break;
		case KeyEvent.VK_LEFT:
			System.out.println("LEFT");
			break;
		case KeyEvent.VK_RIGHT:
			System.out.println("RIGHT");
			break;
		default:
			break;
		}
	}
}
